using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ClassManager {
	
	static string typeName = typeof(CharacterClass).ToString();
	
	static GenericManager<CharacterClass> _m;
	
	static GenericManager<CharacterClass> m
	{
		get
		{
			if(_m == null)
				_m = new GenericManager<CharacterClass>(typeName);
			return _m;
		}
	}
	
	public static Dictionary<string,string> index
	{
		get
		{
			return m.index;
		}
	}
	
	public static CharacterClass Load(string name)
	{
		CharacterClass c = m.LoadObject(name);
		c.SetLevel(1);
		return c;
	}
	
	public static bool isCustom(string name)
	{
		return m.isCustom(name);
	}
	
	public static CharacterClass AddClass(	string name, string description, int hitDie, bool MagicUser, bool ArcaneCaster,
											string SpellList, string castingAbility, bool fortFavored, bool refFavored, 
											bool willFavored, string BABProgression, int skillsPerLevel, List<string> classSkills,
											Dictionary<int, List<string>> abilities, SpellsTable spellsPerDay = null, 
											SpellsTable spellsKnown = null)
	{
		CharacterClass a = new CharacterClass();
		a.name = name;
		a.hitDie = hitDie;
		a.level = 1;
		a.MagicUser = MagicUser;
		a.ArcaneCaster = ArcaneCaster;
		a.description = description;
		a.SpellList = SpellList;
		if(a.MagicUser)
		{
			a.spellsKnown = spellsKnown;
			a.spellsPerDay = spellsPerDay;
		}
		a.FortFavored = fortFavored;
		a.RefFavored = refFavored;
		a.WillFavored = willFavored;
		a.BABProgression = BABProgression;
		
		a.abilityTable = new Dictionary<int, List<string>>();
		
		a.skillsPerLevel = skillsPerLevel;
		a.classSkills = classSkills;
		a.abilityTable = abilities;
		
		a.SpellcastingAbility = castingAbility;
		
		return m.AddObject(a);
	}
	
	public static CharacterClass LoadClassFromData(	string name, string description, int hitDie, bool MagicUser, bool ArcaneCaster,
											string SpellList, string castingAbility, bool fortFavored, bool refFavored, 
											bool willFavored, string BABProgression, int skillsPerLevel, List<string> classSkills,
											Dictionary<int, List<string>> abilities, SpellsTable spellsPerDay = null, 
											SpellsTable spellsKnown = null)
	{
		CharacterClass a = new CharacterClass();
		a.name = name;
		a.hitDie = hitDie;
		a.level = 1;
		a.MagicUser = MagicUser;
		a.ArcaneCaster = ArcaneCaster;
		a.description = description;
		a.SpellList = SpellList;
		if(a.MagicUser)
		{
			a.spellsKnown = spellsKnown;
			a.spellsPerDay = spellsPerDay;
		}
		a.FortFavored = fortFavored;
		a.RefFavored = refFavored;
		a.WillFavored = willFavored;
		a.BABProgression = BABProgression;
		
		a.abilityTable = new Dictionary<int, List<string>>();
		
		a.skillsPerLevel = skillsPerLevel;
		a.classSkills = classSkills;
		a.abilityTable = abilities;
		
		a.SpellcastingAbility = castingAbility;
		
		return a;
	}
	
	public static bool SaveClass(CharacterClass a, string file)
	{
		return m.SaveObject(a, file);
	}
	
	public static void DeleteClass(string name)
	{
		m.DeleteObject(name);
	}
}
